﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wozuji.Logic;


public partial class setFace : Wozuji.Logic.PageLogin
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Header.Title = "足迹网 上传头像 头像自动裁剪";
        try
        {



            
            username.Text = HttpContext.Current.Session["member_name"].ToString();
            source.Text = HttpContext.Current.Session["member_money"].ToString();

        }
        catch (Exception ex)
        {

            // Response.Redirect("/u/userlogin.aspx");

        }

        if (Page.IsPostBack) return;

        if (!string.IsNullOrEmpty(Request.QueryString["Picurl"]))
        {
            //ImageDrag.ImageUrl = Request.QueryString["Picurl"];
            ImageIcon.ImageUrl = Request.QueryString["Picurl"];
            Page.ClientScript.RegisterStartupScript(typeof(setFace), "step2", "<script type='text/javascript'>Step2();</script>");
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(typeof(setFace), "step1", "<script type='text/javascript'>Step1();</script>");
            Wozuji.Model.Member_t mb = new Wozuji.Model.Member_t();
            Wozuji.DAL.Member_t mbdal = new Wozuji.DAL.Member_t();
            mb = mbdal.GetModel_ByMemberId(Convert.ToInt32(Session["userid"]));
            username.Text = mb.Member_Name;


        }
    }
    private const string savepath = "/u/UserHeadImage" + "/";

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (fuPhoto.PostedFile != null && fuPhoto.PostedFile.ContentLength > 0)
        {

            string ext = System.IO.Path.GetExtension(fuPhoto.PostedFile.FileName).ToLower();
            if (ext != ".jpg" && ext != ".jepg" && ext != ".bmp" && ext != ".gif")
            {
                return; //notice user change file type
            }
            string filename = "zuji_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ext;
            string path = "/u/UploadPhoto/" + filename;
            fuPhoto.PostedFile.SaveAs(Server.MapPath(path));
            Response.Redirect("/u/setFace.aspx?Picurl=" + Server.UrlEncode(path));
        }
        else
        {
            //do some thing;notice user select file ；
        }
    }

    protected void btn_Image_Click(object sender, EventArgs e)
    {
        int imageWidth = Int32.Parse(txt_width.Text);
        int imageHeight = Int32.Parse(txt_height.Text);
        int cutTop = Int32.Parse(txt_top.Text);
        int cutLeft = Int32.Parse(txt_left.Text);
        int dropWidth = Int32.Parse(txt_DropWidth.Text);
        int dropHeight = Int32.Parse(txt_DropHeight.Text);

        string filename = Wozuji.Logic.CutPhotoHelp.SaveCutPic(Server.MapPath(ImageIcon.ImageUrl), Server.MapPath(savepath), 0, 0, dropWidth,
                                dropHeight, cutLeft, cutTop, imageWidth, imageHeight);

        this.imgphoto.ImageUrl = savepath + filename;
        Wozuji.Model.Member_t mb = new Wozuji.Model.Member_t();
        Wozuji.BLL.Member_t mbbll = new Wozuji.BLL.Member_t();
        mb = mbbll.GetModel(Convert.ToInt32(Session["userid"].ToString()));
        mb.Member_Face = filename;
        mb.Member_Money = mb.Member_Money + 1;
        mb.Member_ActiveValue = mb.Member_ActiveValue + 2;
        mbbll.Update(mb);

        Page.ClientScript.RegisterStartupScript(typeof(setFace), "step3", "<script type='text/javascript'>Step3();</script>");

    }
}

